import request from '@/utils/request.ts'
import type { Category, CategoryResponseData } from './type'

enum API {
  //获取全部分类数据
  CATEGORY_GETALL_URL = '/category/admin/getall/',
  //添加分类
  ADD_CATEGORY_URL = '/category/admin/create/',
  //查询特定分类
  CATEGORY_URL = '/category/admin/get/',
  //修改
  UPDATE_CATEGORY_URL = '/category/admin/update/',
  //删除
  DELETE_CATEGORY_URL = '/category/admin/delete/',
}

export const reqHasCategory = () =>
  request.get<any, CategoryResponseData>(API.CATEGORY_GETALL_URL)

export const reqAddCategory = (data: Category) => {
  return request.post<any, any>(API.ADD_CATEGORY_URL, data)
}

export const reqUpdateCategory = (data: Category) => {
  return request.put<any, any>(API.UPDATE_CATEGORY_URL, data)
}

export const reqDeleteCategory = (id: number) =>
  request.delete<any, any>(API.DELETE_CATEGORY_URL + id + '/')
